//
//  BHCircleDetailInfoModel.swift
//  BigHealth
//
//  Created by 蔺百好 on 2021/7/12.
//

import UIKit

class BHCircleDetailInfoModel: NSObject {
    var circleId: String = ""
    var userId: String = ""
    var userName: String = ""
    var userAvatar: String = ""
    var title: String = ""
    var content: String = ""
    var relationId: String = "" // 关联id
    var relationName: String = ""
    var relationPic: String = "" // 关联封面
    var cityName: String = ""
    var areaName: String = ""
    var distance: String = ""
    var beginTime: String = ""  //关联 开始时间
    var place: String = "" // 地址
    var createTime: String = "" // 发布时间
    var longitude: String = ""
    var latitude: String = ""
    
    
    var likeFlag: Int = 0 // 是否点赞圈子  0:否 1:是
    var attentionFlag: Int = 0 // 是否关注用户  0:否  1:是
    var commentNum: Int = 0 // 全部评论数
    
    var supportNumber: Int = 0
    var resourceType: Int = 0 // 资源类型 1图片 2视频
    var relationType: Int = 0 // 关联类型 1场馆 2赛事 3趣玩
    
    
    var circleUrlList: [String] = []
    
    
    func parseDic(_ dic: [String: Any])  {
        self.circleId = BHJsonTool.decodeStringFromDic(dic: dic, key: "id")
        self.userId = BHJsonTool.decodeStringFromDic(dic: dic, key: "userId")
        self.userName = BHJsonTool.decodeStringFromDic(dic: dic, key: "userName")
        self.userAvatar = BHJsonTool.decodeStringFromDic(dic: dic, key: "userAvatar")
        self.title = BHJsonTool.decodeStringFromDic(dic: dic, key: "title")
        self.content = BHJsonTool.decodeStringFromDic(dic: dic, key: "content")
        self.relationId = BHJsonTool.decodeStringFromDic(dic: dic, key: "relationId")
        self.relationName = BHJsonTool.decodeStringFromDic(dic: dic, key: "relationName")
        self.relationPic = BHJsonTool.decodeStringFromDic(dic: dic, key: "relationPic")
        self.cityName = BHJsonTool.decodeStringFromDic(dic: dic, key: "cityName")
        self.areaName = BHJsonTool.decodeStringFromDic(dic: dic, key: "areaName")
        self.distance = BHJsonTool.decodeStringFromDic(dic: dic, key: "distance")
        self.beginTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "beginTime")
        self.place = BHJsonTool.decodeStringFromDic(dic: dic, key: "place")
        self.createTime = BHJsonTool.decodeStringFromDic(dic: dic, key: "createTime")
        self.longitude = BHJsonTool.decodeStringFromDic(dic: dic, key: "longitude")
        self.latitude = BHJsonTool.decodeStringFromDic(dic: dic, key: "latitude")

        self.likeFlag = BHJsonTool.decodeIntFromDic(dic: dic, key: "likeFlag")
        self.attentionFlag = BHJsonTool.decodeIntFromDic(dic: dic, key: "attentionFlag")
        self.commentNum = BHJsonTool.decodeIntFromDic(dic: dic, key: "commentNum")
        self.supportNumber = BHJsonTool.decodeIntFromDic(dic: dic, key: "supportNumber")
        self.resourceType = BHJsonTool.decodeIntFromDic(dic: dic, key: "resourceType")
        self.relationType = BHJsonTool.decodeIntFromDic(dic: dic, key: "relationType")
        
        let url = BHJsonTool.decodeArrayFromDic(dic: dic, key: "circleUrlList")
        if self.circleUrlList.count != 0 {
            self.circleUrlList.removeAll()
        }
        
        for item in url {
            if item is NSNull {
                continue
            }else {
                self.circleUrlList.append(item as! String)
            }
        }

    }
    
    lazy var showContentText: NSMutableAttributedString = {
        if self.content.isEmpty == true {
            return NSMutableAttributedString.init(string: "")
        }else {
            let attribute = self.content.toAttribute().addLineSpace(5)
            attribute.addFont(.systemFont(ofSize: 14, weight: .medium))
            attribute.addAllTextColor(.color_222222)
            return attribute
        }
    }()
    
    lazy var title_height: CGFloat = {
        if self.title.isEmpty == true {
            return 0
        }else {
            let  height_ = self.title.calSizeOfText(font: .systemFont(ofSize: 16, weight: .bold), size: CGSize(width: UIScreen.width-32, height: CGFloat.greatestFiniteMagnitude)).height
            return ceil(height_)
        }
    }()
    
    lazy var contentHeight: CGFloat = {
        let hei = self.showContentText.calculateSize(CGSize(width: UIScreen.width-32, height: CGFloat.greatestFiniteMagnitude)).height
        return ceil(hei)
    }()
    
    
}
